package com.voxel.sense.infomsg.widget.map;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.com.common.utils.PhoneUtils;
import com.example.com.common.utils.SizeUtils;
import com.example.com.common.utils.ToastUtil;
import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;
import cyy.example.com.facotry.Factory;

/**
 * Created by ChenYiYao on 2018/8/27.
 */
public class MapStaffInfoPopWindows extends BottomSheetDialog {

    private RecyclerAdapter mAdapter;
    private TextView tv_name;
    private TextView tv_department;//所属部门类型
    private TextView tv_user_job;//用户岗位
    private TextView tv_email; //邮箱
    private TextView tv_phone; //电话
    private ImageView iv_phone; //电话
    private RecyclerView recycle_view;

    public MapStaffInfoPopWindows(@NonNull Context context) {
        super(context, 0);
//        super(context, R.style.MyDialog);
        //设置自定义视图
        View inflate = LayoutInflater.from(context).inflate(R.layout.dialog_staff_marker_info, null);
        tv_name = inflate.findViewById(R.id.tv_name);
        tv_department = inflate.findViewById(R.id.tv_department);
        tv_user_job = inflate.findViewById(R.id.tv_user_type);
        tv_email = inflate.findViewById(R.id.tv_email);
        tv_phone = inflate.findViewById(R.id.tv_phone);
        iv_phone = inflate.findViewById(R.id.iv_phone);
        setContentView(inflate);
        //是否可取消
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        //去除外围的灰色遮罩
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);


        //设置初始显示高度
        BottomSheetBehavior<View> from = BottomSheetBehavior.from((View) inflate.getParent());
        from.setPeekHeight(SizeUtils.dp2px(165));

        //设置拨号按钮事件
        iv_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isDigitsOnly(tv_phone.getText().toString())) {
                    PhoneUtils.dial(tv_phone.getText().toString());
//                    IntentUtils.getDialIntent(phone)
                } else {
                    ToastUtil.showToastLong(Factory.app(), "号码格式不正确");
                }

            }
        });
    }


    public void show(String name, String deparment, String job, String email, String phone) {
        tv_name.setText(name);

        job = deparment;
        deparment = "";
        if (TextUtils.isEmpty(deparment)) {
            tv_department.setVisibility(View.GONE);
        } else {
            tv_department.setVisibility(View.VISIBLE);
            tv_department.setText(deparment);
        }

        if (TextUtils.isEmpty(job)) {
            tv_user_job.setVisibility(View.GONE);
        } else {
            tv_user_job.setVisibility(View.VISIBLE);
            tv_user_job.setText(job);
        }
        if (TextUtils.isEmpty(email)) {
            tv_email.setVisibility(View.GONE);
        } else {
            tv_email.setVisibility(View.VISIBLE);
            tv_email.setText(email);
        }
        if (TextUtils.isEmpty(phone)) {
            tv_phone.setVisibility(View.GONE);
            iv_phone.setVisibility(View.INVISIBLE);
        } else {
            tv_phone.setVisibility(View.VISIBLE);
            iv_phone.setVisibility(View.VISIBLE);
            tv_phone.setText(phone);
        }

        show();
    }

}
